//
//  ShippingAddressTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/18.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "ShippingAddressTableViewCell.h"

#import "ShippingAddressAddViewController.h"

@interface ShippingAddressTableViewCell ()

@property (strong, nonatomic) UILabel *nameL;
@property (strong, nonatomic) UILabel *phoneL;
@property (strong, nonatomic) UILabel *addressL;
@property (strong, nonatomic) UILabel *statusL;
@property (strong, nonatomic) UIView *lineL;
@property (strong, nonatomic) UIImageView *separatorL;

@property (strong, nonatomic) UIImageView *morenAddressIV;
@property (strong, nonatomic) UILabel *morenAdressL;

@end

@implementation ShippingAddressTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.nameL];
        [self.contentView addSubview:self.phoneL];
        [self.contentView addSubview:self.addressL];
        [self.contentView addSubview:self.statusL];
        [self.contentView addSubview:self.lineL];
        [self.contentView addSubview:self.separatorL];
        [self.contentView addSubview:self.morenAddressIV];
        [self.contentView addSubview:self.morenAdressL];
        
    }
    
    return self;
}

- (void)setShippingModel:(ShippingAdressModel *)shippingModel {
    
    _shippingModel = shippingModel;
    
    self.nameL.text = shippingModel.name;
    self.phoneL.text = shippingModel.phone;
    self.addressL.text = shippingModel.address;
    
    if ([shippingModel.isdefault boolValue]) {
        // 默认地址
        
        self.morenAdressL.hidden = NO;
        self.morenAddressIV.hidden = NO;
        
    }else {
        
        self.morenAddressIV.hidden = YES;
        self.morenAdressL.hidden = YES;
        
    }
    
}

#pragma mark -编辑按钮点击
- (void)statusGestureClick:(UIGestureRecognizer *)gesture {
    
    NSLog(@"地址编辑");
    
    ShippingAddressAddViewController *vc = [[ShippingAddressAddViewController alloc] init];
    vc.title = @"修改地址";
    vc.shippingModel = self.shippingModel;
    
    [self.parentVC.navigationController pushViewController:vc animated:YES];
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.nameL sizeToFit];
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(jisuan(18));
        if (self.nameL.text) {
            
            make.width.mas_equalTo(weakSelf.nameL.width);
            make.height.mas_equalTo(weakSelf.nameL.height);
            
        }
        
    }];
    [self.statusL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(40));
        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.width.mas_equalTo(jisuan(52));
        make.height.mas_equalTo(jisuan(34));
        
    }];
    [self.lineL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.right.mas_equalTo(weakSelf.statusL.mas_left).with.offset(-jisuan(28));
        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.width.mas_equalTo(jisuan(2));
        make.height.mas_equalTo(jisuan(80));

    }];
    [self.phoneL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.nameL.mas_right).with.offset(jisuan(36));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(jisuan(18));
        make.right.mas_equalTo(weakSelf.lineL.mas_left).with.offset(-jisuan(48));

    }];
    [self.addressL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(40));
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(20));
        make.right.mas_equalTo(weakSelf.lineL.mas_left).with.offset(-jisuan(48));

    }];
    [self.separatorL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom);
        make.centerX.mas_equalTo(weakSelf.contentView.mas_centerX);
        make.width.mas_equalTo(jisuan(714));
        make.height.mas_equalTo(jisuan(4));

    }];
    
    [self.morenAddressIV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(weakSelf.nameL.mas_centerY);
        make.right.mas_equalTo(weakSelf.lineL.mas_left).with.offset(-jisuan(48));
        make.width.mas_equalTo(jisuan(112));
        make.height.mas_equalTo(jisuan(32));
        
    }];
    [self.morenAdressL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(weakSelf.morenAddressIV.mas_centerY);
        make.centerX.mas_equalTo(weakSelf.morenAddressIV.mas_centerX);
        
    }];
    
    
}

#pragma mark -lazy
- (UILabel *)nameL {

    if (!_nameL) {
        
        _nameL = [[UILabel alloc] init];
//        _nameL.text = @"名字";
        _nameL.textAlignment = NSTextAlignmentLeft;
        _nameL.textColor = Color333333;
        _nameL.font = Font(24);
    }
    
    return _nameL;
}
- (UILabel *)phoneL {
    
    if (!_phoneL) {
        
        _phoneL = [[UILabel alloc] init];
//        _phoneL.text = @"184*****375";
        _phoneL.textAlignment = NSTextAlignmentLeft;
        _phoneL.textColor = Color333333;
        _phoneL.font = Font(24);
    }
    
    return _phoneL;
}
- (UILabel *)addressL {
    
    if (!_addressL) {
        
        _addressL = [[UILabel alloc] init];
//        _addressL.text = @"北京朝阳区三环到四环之间 建外SOHO11号楼2605";
        _addressL.textAlignment = NSTextAlignmentLeft;
        _addressL.textColor = Color333333;
        _addressL.font = Font(24);
    }
    
    return _addressL;
}

- (UILabel *)statusL {
    
    if (!_statusL) {
        
        _statusL = [[UILabel alloc] init];
        _statusL.text = @"编辑";
        _statusL.textAlignment = NSTextAlignmentLeft;
        _statusL.textColor = Color999999;
        _statusL.font = Font(24);
        _statusL.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *statusGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(statusGestureClick:)];
        [_statusL addGestureRecognizer:statusGesture];
    }
    
    return _statusL;
}
- (UIView *)lineL {
    
    if (!_lineL) {
        
        _lineL = [[UIView alloc] init];
        _lineL.backgroundColor = Colordddddd;
        
    }
    return _lineL;
}

- (UIImageView *)separatorL {
    
    if (!_separatorL) {
        
        _separatorL = [[UIImageView alloc] init];
        _separatorL.contentMode = UIViewContentModeScaleAspectFit;
        _separatorL.image = [UIImage imageNamed:@"purchaseLineBG"];
    }

    return _separatorL;
}
- (UIImageView *)morenAddressIV {
    
    if (!_morenAddressIV) {
        
        _morenAddressIV = [[UIImageView alloc] init];
        _morenAddressIV.contentMode = UIViewContentModeScaleAspectFit;
        _morenAddressIV.image = [UIImage imageNamed:@"morenAddressbg@3x"];
    }
    
    return _morenAddressIV;
}
- (UILabel *)morenAdressL {
    
    if (!_morenAdressL) {
        
        _morenAdressL = [[UILabel alloc] init];
        _morenAdressL.text = @"默认地址";
        _morenAdressL.textColor = Colorff0000;
        _morenAdressL.font = Font(20);
        _morenAdressL.textAlignment = NSTextAlignmentCenter;
    }
    
    return _morenAdressL;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
